package com.asiainfo.dacp.datastash.orm.dao.state;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.asiainfo.dacp.datastash.orm.po.state.DataStashUnitStateLogPo;

@Repository
public interface DataStashUnitStateLogDao extends JpaRepository<DataStashUnitStateLogPo,String>,JpaSpecificationExecutor<DataStashUnitStateLogPo> {

    @Query("from DataStashUnitStateLogPo p where p.unitCode=:unitCode and p.batchNo=:batchNo and p.isOver='1'")
    List<DataStashUnitStateLogPo> findUnitStateNonOver(@Param("unitCode") String unitCode, @Param("batchNo") String batchNo);

    
    @Transactional
    @Modifying
    @Query("update DataStashUnitStateLogPo p set p.isOver=:isOver where p.unitProcId=:unitProcId")
    void updateIsOver(@Param("unitProcId") String unitProcId,@Param("isOver") String isOver);
    
    @Transactional
    @Modifying
    @Query("update DataStashUnitStateLogPo p set p.isOver=:isOver where p.unitCode=:unitCode and p.batchNo=:batchNo")
    void updateIsOver(@Param("unitCode") String unitCode, @Param("batchNo") String batchNo ,@Param("isOver") String isOver);
    
    

    @Transactional
    @Modifying
    @Query("update DataStashUnitStateLogPo p set p.isOver='0' where p.unitProcId=:unitProcId")
    void updateOver(@Param("unitProcId") String unitProcId);

}

